<template>
    <view class="page">
        <view class="header_box">
            <view class="pic_box">
                <view class="header_yue_box">
                    <view class="header_num_box">{{ yue }}</view>
                    <view class="header_name_box">大王币</view>
                </view>
            </view>
        </view>
        <view class="expense_box">消费记录</view>
        <scroll-view scroll-y class="content_box" @scrolltolower="lower()">
            <view @click="goDetial(item)" class="dange_box" v-for="item,index in consumptionList" :key="index">
                <view class="dange_name_box">
                    {{ item.desc }}
                </view>
                <view class="dange_name_box">
                    <view class="leftbox">{{ item.create_time | formatDate('-') }}</view>
                    <view class="rightbox">{{ item.num }}</view>
                </view>
            </view>
        </scroll-view>
        <view class="tokenredpackets" @click="packetsBtn">合成代币红包</view>
    </view>
</template>
<script>
export default {
    data() {
        return {
            page: 1,
            flag: true,
            consumptionList: [],//消费列表
            yue:'',//余额
        }
    },
    filters: {
		// 时间戳处理
		formatDate: function (value, spe = '/') {
			value = value * 1000
			let data = new Date(value);
			let year = data.getFullYear();
			let month = data.getMonth() + 1;
			let day = data.getDate();
			let h = data.getHours();
			let mm = data.getMinutes();
			let s = data.getSeconds();
			month = month >= 10 ? month : "0" + month;
			day = day >= 10 ? day : "0" + day;
			h = h >= 10 ? h : "0" + h;
			mm = mm >= 10 ? mm : "0" + mm;
			s = s >= 10 ? s : "0" + s;
			return `${year}${spe}${month}${spe}${day} ${h}:${mm}:${s}`;
		}
	},
    onShow() {
        this.getyue()
        this.conList()
    },
    methods: {
		// 去详情
		goDetial(item){
			console.log(item)
			uni.navigateTo({
				url:'/packet/envelopeDetails?id=' + item.id
			})
		},
        lower() {
            uni.showToast({
                title: "没有更多了",
                icon: 'none'
            })
        },
        getyue() {
            let init = {
                integral: 1
            }
            this.$Request.get(this.$api.user.index, init).then(res => {
                this.yue = res.data.integral
            })
        },
        // 消费列表
        conList() {
            let data = {
                page: this.page
            }
            uni.showLoading({
                title: "加载中..."
            })
            this.$Request.get(this.$api.user.packetPacketLog, data).then(res => {
                uni.hideLoading()
                var consumptionList = res.data.list;
                this.page++;
                this.consumptionList = this.consumptionList.concat(consumptionList);// 拼接回来的数据
                // 当回来的数据小于十条得时候 不让再请求了 否则继续请求
                if (consumptionList.length < 10) {
                    this.flag = false
                } else {
                    this.flag = true
                }
            })
        },
        // 合成代币红包
        packetsBtn() {
            uni.navigateTo({
                url: '/packet/packetdetail'
            })
        }
    }
}
</script>
<style lang="scss" scoped>
.page {
    width: 100vw;
    min-height: 100vh;
    background-color: #262626;

    .header_box {
        width: 693rpx;
        height: 238rpx;
        margin: auto;
        position: relative;
        margin-bottom: 52rpx;

        .pic_box {
            width: 693rpx;
            height: 191rpx;
            // background: #393834;
            opacity: 1;
            // border: 1rpx solid #D1D1D1;
            position: absolute;
            background-image: url('https://new.qingfentool.vip/upload/image/20230821/17078eb4171fbeeb11d5341cda50b3ad.png');
            background-size: 100% 100%;
            bottom: 0;

            .header_yue_box {
                position: absolute;
                right: 35rpx;
                bottom: 26rpx;

                .header_num_box {
                    height: 79rpx;
                    font-size: 60rpx;
                    font-family: Microsoft YaHei-Bold, Microsoft YaHei;
                    font-weight: bold;
                    color: #F8B857;
                }

                .header_name_box {
                    height: 40rpx;
                    font-size: 30rpx;
                    font-family: Microsoft YaHei-Regular, Microsoft YaHei;
                    font-weight: 400;
                    color: #FFFFFF;
                    text-align: right;
                }
            }
        }
    }

    .expense_box {
        width: 693rpx;
        height: 40rpx;
        margin: auto;
        font-size: 30rpx;
        font-family: Microsoft YaHei-Regular, Microsoft YaHei;
        font-weight: 400;
        color: #FFFFFF;
        line-height: 20rpx;
        margin-bottom: 23rpx;
    }

    .content_box {
        width: 100%;
        height: calc(100vh - 530rpx);
        margin-bottom: 30rpx;

        .dange_box {
            width: 693rpx;
            height: 123rpx;
            background: #393834;
            border-radius: 20rpx 20rpx 20rpx 20rpx;
            opacity: 1;
            border: 1rpx solid #D8D6AF;
            margin: auto;
            margin-bottom: 20rpx;
            padding: 22rpx 18rpx 0 18rpx;

            .dange_name_box {
                width: 100%;
                height: 37rpx;
                font-size: 28rpx;
                font-family: Microsoft YaHei-Regular, Microsoft YaHei;
                font-weight: 400;
                color: #D1D1D1;
                line-height: 36rpx;
                display: flex;
                justify-content: space-between;
                align-items: center;
                margin-bottom: 12rpx;

                .leftbox {
                    height: 29rpx;
                    font-size: 22rpx;
                    font-family: Microsoft YaHei-Regular, Microsoft YaHei;
                    font-weight: 400;
                    color: #A4A4A4;
                    line-height: 36rpx;
                }

                .rightbox {
                    height: 37rpx;
                    font-size: 28rpx;
                    font-family: Microsoft YaHei-Regular, Microsoft YaHei;
                    font-weight: 400;
                    color: #F8B857;
                    line-height: 36rpx;
                }
            }
        }
    }

    .tokenredpackets {
        width: 693rpx;
        height: 96rpx;
        background: linear-gradient(177deg, #FFE2B7 0%, #F5B143 100%);
        border-radius: 20rpx 20rpx 20rpx 20rpx;
        opacity: 1;
        font-size: 36rpx;
        font-family: Microsoft YaHei-Regular, Microsoft YaHei;
        font-weight: 400;
        color: #000000;
        line-height: 96rpx;
        text-align: center;
        margin: auto;
    }
}
</style>